
# Step1
class Distance:
    # Step2 & Step3. 定义属性，并根据属性定义构造函数
    def __init__(self, meters: int, m: int, n: int):
        self.meters = meters # 答案
        self.m = m # 每一行的基地个数
        self.n = n # 每一列的基地个数

    def __repr__(self):
        return f"m={self.m} n={self.n} meters={self.meters}"

    # 计算行走距离，并更新 meters 属性
    #Step5. 定义 solution 方法
    def solve(self):
        if self.m == 1:
            self.meters = (self.n - 1) * 2
        elif self.n == 1:
            self.meters = (self.m - 1) * 2
        elif self.m * self.n % 2 == 0:
            self.meters = self.m * self.n
        else:
            self.meters = self.m * self.n - 1 + 1.414

# Step 4. 定义一个准备函数，从输入文件中读取内容，生成自定义类型的对象
def preparation(filename: str) -> Distance:
    f = open(filename, "r")
    line = f.readline() # "3 2"
    word = line.split() # ["3", "2"]

    return Distance(meters = 0, m = word[0], n = word[1])

preparation("steps.in").solve()


